package com.jxc.jxc01.hch.service.Impl;

import com.jxc.jxc01.hch.dao.Impl.WareHouseDaoImpl;
import com.jxc.jxc01.hch.dao.WareHouseDao;
import com.jxc.jxc01.hch.entity.PageHelper;
import com.jxc.jxc01.hch.entity.WareHouse;
import com.jxc.jxc01.hch.service.IWareHouseService;

import java.text.SimpleDateFormat;
import java.util.Date;

public class IWareHouseServiceImpl implements IWareHouseService {
    WareHouseDao wareHouseDao = new WareHouseDaoImpl();
    @Override
    public PageHelper<WareHouse> list(PageHelper<WareHouse> pageHelper) {
        wareHouseDao.list(pageHelper);
        int pageCount = (pageHelper.getTotal()%pageHelper.getPageSize())==0?pageHelper.getTotal()/pageHelper.getPageSize():pageHelper.getTotal()/pageHelper.getPageSize()+1;
        pageHelper.setPageCount(pageCount);
        return pageHelper;
    }

    @Override
    public PageHelper<WareHouse> query(PageHelper<WareHouse> pageHelper, String username) {
        wareHouseDao.query(pageHelper,username);
        int pageCount = (pageHelper.getTotal()%pageHelper.getPageSize())==0?pageHelper.getTotal()/pageHelper.getPageSize():pageHelper.getTotal()/pageHelper.getPageSize()+1;
        pageHelper.setPageCount(pageCount);
        return pageHelper;
    }

    @Override
    public int increase(WareHouse wareHouse) {
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //接收时间日期
        String s = sdf.format(date);
        wareHouse.setCreationtime(s);
        return wareHouseDao.increase(wareHouse);
    }

    @Override
    public int modify(WareHouse wareHouse) {
        return wareHouseDao.modify(wareHouse);
    }

    @Override
    public int delete(int id) {
        return wareHouseDao.delete(id);
    }
}
